package com.thb.pay.manage.web.payment;


import com.thb.pay.api.payment.PaySceneServiceApi;
import com.thb.pay.api.payment.vo.req.PayScenePageReq;
import com.thb.pay.api.payment.vo.req.PaySceneReq;
import com.thb.pay.api.payment.vo.resp.PaySceneVo;
import com.thb.pay.core.utils.PageResult;
import com.thb.pay.core.utils.R;
import com.thb.pay.manage.comm.controller.BaseController;
import com.xiaoleilu.hutool.collection.CollUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 支付-情景表 前端控制器
 * </p>
 *
 * @author lucky
 * @since 2019-07-21
 */
@Slf4j
@RestController
@RequestMapping("api/sys/payScene")
public class PaySceneController extends BaseController {

    @Autowired
    private PaySceneServiceApi paySceneServiceApi;

    @PostMapping("/list")
    public R list(@RequestBody PayScenePageReq pageReq) {
        PageResult<PaySceneVo> pageResult = paySceneServiceApi.findPage(pageReq);
        return R.okData(pageResult);
    }


    @RequestMapping("/allList")
    public R allList() {
        List<PaySceneVo> resultDataList = paySceneServiceApi.findAllList();
        return R.okData(resultDataList);
    }

    @RequestMapping("/get")
    public R get(@RequestParam("id") Long id) {
        PaySceneVo resultData = paySceneServiceApi.getById(id);
        return R.okData(resultData);
    }

    @PostMapping("/add")
    public R add(@RequestBody PaySceneReq paySceneReq) {
        paySceneServiceApi.add(paySceneReq);
        return R.ok();
    }


    @PostMapping("/delete")
    public R delete(@RequestBody List<Long> ids) {
        if (CollUtil.isNotEmpty(ids)) {
            paySceneServiceApi.deleteBatchIds(ids);
        }
        return R.ok();
    }


    @PostMapping("/update")
    public R update(@RequestBody PaySceneReq paySceneReq) {
        paySceneServiceApi.update(paySceneReq);
        return R.ok();
    }
}
